<?php 
class TarifasController extends AppController{
  public $helpers = array('Html', 'Form');
  public $uses = array(
  'Categoriastarifa', 'Tipostarifa', 'Tarifa'
  );
  public $components = array('Session');
  public $layout= 'default';
  
  function index(){
     $tarifas = $this->Tarifa->find('all', array(
            'recursive' => 0,
            'order' => 'Tarifa.categoriastarifa_id ASC',
            'limit' => 15));
        //debug($mascotas);exit;
     $this->set(compact('tarifas'));   
  }
  function insertar($id = null){
        if(!empty($this->data)){
            //debug($this->data);exit;
            $this->Tarifa->create();
            if($this->Tarifa->save($this->data)){
                $this->Session->setFlash("Tarifa ".$this->Tarifa->id." guardada");
                $this->redirect(array('action'=>'index'), null, true);
            }else{
                $this->Session->setFlash("No se pudo guardar");
                $this->redirect(array('action'=>'index'), null, true);
            }
        }else{
            $categorias = $this->Categoriastarifa->find('list', array(
            'fields'=>array('Categoriastarifa.id', 'Categoriastarifa.nombre')
            ));
            $this->set(compact('categorias'));
        }
    }
    function editar($id=null){
        $this->Tarifa->id = $id;
                if (!$id) {
                    $this->Session->setFlash('No existe tal registro');
                    $this->redirect(array('action' => 'index'), null, true);
                }
                if (empty($this->data)) {
                    $this->data = $this->Tarifa->read(); 
                } else {
                	
                    if ($this->Tarifa->save($this->data)) {
                        $this->Session->setFlash('Los datos fueron modificados');
                        $this->redirect(array('action' => 'index'), null, true);
                    } else {
                        $this->Session->setFlash('no se pudo modificar!!');
                    }
                }
        $categorias = $this->Categoriastarifa->find('list', array(
            'fields'=>array('Categoriastarifa.id', 'Categoriastarifa.nombre')
            ));
            $this->set(compact('categorias'));
    }
     public function eliminar($id = null){
        if (!$id) {
            $this->Session->setFlash('id Invalida para borrar');
            $this->redirect(array('action' => 'index'));
        }
        if ($this->Tarifa->delete($id)) {
           $this->Session->setFlash('El Departamento ' . $id . ' fue borrado');
           $this->redirect(array('action' => 'index'));
        }

    }
}
 ?>